package com.mucd.chat.service;

import com.mucd.chat.mapper.FriendSettingMapper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.FriendSetting;
import com.ruoyi.common.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户设置service
 *
 * @author mucd
 */
@Service
@Slf4j
public class FriendSettingService {

    @Resource
    private FriendSettingMapper friendSettingMapper;


    /**
     * 验证指定用户的指定设置是否开启
     * @param userId 用户id
     * @param settingType 设置类型
     * @param message 提示语
     */
    public void checkSetting(Long userId, String settingType,String message) {
        //查询对方的设置
        List<FriendSetting> setting = friendSettingMapper.selectSettingByUserId(userId);

        setting.forEach(item -> {
            //判断对方好友是否允许添加好友
            if (item.getSettingType().equals(settingType) && item.getSettingType().equals(Constants.FRIEND_SETTING_ALLOW_ADD_FRIEND_0)) {
                throw new ServiceException(message);
            }
        });

    }

}
